let Book = (function () {
    //静态私有变量
    let bookNum = 0;
    //静态私有方法
    function checkBook() {console.log('我是静态私有方法！')}
    function _book(newId, newName, newPrice) {
        if (!(this instanceof Book)) {
            return new Book(newId, newName, newPrice);
        }
        //私有变量
        let name, price;
        //私有方法
        function checkID() {console.log('我是私有方法！')}
        //特权方法
        this.getName = function () { return name };
        this.setName = function (nm) { name = nm };
        this.getPrice = function () { return price };
        this.setPrice = function (pr) { price = pr };
        //公有属性
        this.id = newId;
        bookNum++;
        if (bookNum > 2) {throw new Error('我们仅出版2本书');}
        //构造器
        this.setName(newName);
        this.setPrice(newPrice);
    }
    _book.prototype = {
        isJSBook: false,
        display: function () {
            console.log(this.getName(), this.getPrice());
        }
    };
    return _book;
})();

let b1 = new Book(11, 'JavaScript设计模式', 50);
b1.display();
b1.setName('我换书名啦');
b1.display();
console.log(b1 instanceof Book);
let b2 = Book(12, 'JavaScript语言精粹', 60);
b2.display();
